package net.lab1024.smartadmin.module.business.engineThousand.controller;

import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.engineReverse.domain.entity.EngineReverseEntity;
import net.lab1024.smartadmin.module.business.engineThousand.domain.dto.EngineThousandAddDTO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.dto.EngineThousandUpdateDTO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.dto.EngineThousandQueryDTO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.entity.EngineThousandEntity;
import net.lab1024.smartadmin.module.business.engineThousand.domain.vo.EngineThousandVO;
import net.lab1024.smartadmin.module.business.engineThousand.domain.vo.EngineThousandExcelVO;
import net.lab1024.smartadmin.module.business.engineThousand.service.EngineThousandService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ 发动机万有特性 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 发动机万有特性
 * @copyright (c)  发动机万有特性Inc. All rights reserved.
 * @date 2021-11-07 11:20:13
 * @since JDK1.8
 */
@RestController
@Api(tags = {"发动机万有特性"})
public class EngineThousandController extends BaseController {

    @Autowired
    private EngineThousandService engineThousandService;

    @ApiOperation(value = "分页查询发动机万有特性",notes = "@author wuhq")
    @PostMapping("/engineThousand/page/query")
    public ResponseDTO<PageResultDTO<EngineThousandVO>> queryByPage(@RequestBody EngineThousandQueryDTO queryDTO) {
        return engineThousandService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "根据id获取数据",notes = "@author wuhq")
    @GetMapping("/engineThousand/getById/{id}")
    public ResponseDTO<EngineThousandEntity> getById(@PathVariable Long id) {
        return ResponseDTO.succData(engineThousandService.getById(id));
    }

    @ApiOperation(value = "根据发动机id获取数据",notes = "@author wuhq")
    @GetMapping("/engineThousand/getByEngineId/{engineId}")
    public ResponseDTO<EngineThousandEntity> getByEngineId(@PathVariable Long engineId) {
        return ResponseDTO.succData(engineThousandService.getByEngineId(engineId));
    }


    @ApiOperation(value = "添加发动机万有特性",notes = "@author wuhq")
    @PostMapping("/engineThousand/add")
    public ResponseDTO<String> add(@RequestBody @Validated EngineThousandAddDTO addTO){
        engineThousandService.delByEngineId(addTO.getEngineId());
        return engineThousandService.add(addTO);
    }

    @ApiOperation(value="修改发动机万有特性",notes = "@author wuhq")
    @PostMapping("/engineThousand/update")
    public ResponseDTO<String> update(@RequestBody @Validated EngineThousandUpdateDTO updateDTO){
        return engineThousandService.update(updateDTO);
    }

    @ApiOperation(value="批量删除发动机万有特性",notes = "@author wuhq")
    @PostMapping("/engineThousand/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return engineThousandService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author wuhq")
    @PostMapping("/engineThousand/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<EngineThousandExcelVO> engineThousandList = engineThousandService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("发动机万有特性", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, EngineThousandExcelVO.class, engineThousandList);
        downloadExcel("发动机万有特性", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wuhq")
    @PostMapping("/engineThousand/export/all")
    public void exportAll(@RequestBody @Validated EngineThousandQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<EngineThousandExcelVO> engineThousandList = engineThousandService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("发动机万有特性", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, EngineThousandExcelVO.class, engineThousandList);
        downloadExcel("发动机万有特性", workbook, response);
    }

}
